@tool
class_name FleeContextBehavior
extends BaseContextBehavior

#region 属性
@export var flee_radius:float
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func init_context(steering_component:SteeringComponent,resolution_radio:int):
	super.init_context(steering_component,resolution_radio)
func get_interest(entity:CharacterEntity,directions:Array[Vector2]) -> Array[float]:
	interest = []
	interest.resize(directions.size())
	return interest
func get_danger(entity:CharacterEntity,directions:Array[Vector2]) -> Array[float]:
	danger = []
	danger.resize(directions.size())
	var detector = entity.get_detector(GameEnum.DetectorType.Target)
	if not detector:
		return danger
	var closed_visible_entity = detector.get_closed_entity(GameEnum.TargetDetectorTargetType.VisibleTarget,global_position)
	if not closed_visible_entity:
		return danger
	var target_dir:Vector2 = (closed_visible_entity.get_pos() - global_position).normalized()
	var distance:float = (closed_visible_entity.get_pos() - global_position).length()
	for i in range(directions.size()):
		danger[i] = directions[i].dot(target_dir) * flee_radius / distance * sensitive;
		if entity.test_move(entity.global_transform,entity.get_entity_data().get_scale_move_speed() * directions[i] * steering_component.update_dalay):
			danger[i] += 1/(entity.get_entity_data().get_scale_move_speed() * steering_component.update_dalay) * sensitive
	return danger
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _draw() -> void:
	super._draw()
#endregion
